package com.sisgh.jefdv1;

import com.sisgh.jefdv1.core.entity.Entities;
import com.sisgh.jefdv1.core.entity.Entity;
import com.sisgh.jefdv1.core.jdbc.connection.ConnectionFactoryBuilder;
import com.sisgh.jefdv1.core.jdbc.connection.factory.ConnectionFactory;
import com.sisgh.jefdv1.core.jdbc.connection.properties.ConnectionProperties;
import com.sisgh.jefdv1.core.jdbc.db.Database;
import com.sisgh.jefdv1.core.jdbc.table.Table;
import com.sisgh.jefdv1.core.jdbc.table.Tables;
import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

@Slf4j
public class Main {

    private static final String url = "jdbc:mysql://localhost:3306/ms?serverTimezone=Asia/Shanghai";
    private static final String user = "root";
    private static final String password = "root";


    public void testTables() throws SQLException {
        ConnectionFactory connectionFactory = ConnectionFactoryBuilder.getConnectionFactory(Database.MYSQL);

        ConnectionProperties cp = new ConnectionProperties(url, user, password);

        Connection connection = connectionFactory.getConnection(cp);

        List<Table> tables = Tables.fetchTables(connection);

        for (Table table : tables) {
            System.out.println(table);
        }

        List<Entity> entities = Entities.convertToEntities(tables);

        System.out.println(entities.size());
    }

    public static void main(String[] args) {
        try {
            new Main().testTables();
        } catch (SQLException e) {
            log.error(e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
